import { fileURLToPath, URL } from 'node:url'
import UnoCSS from 'unocss/vite'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    server: {
      open: true,
      host: true,
      proxy: {
        '/bdsaas': {
          target: env.VITE_API_URL,
          changeOrigin: true,
        },
        '/call-robot-engine': {
          target: env.VITE_API_URL,
          changeOrigin: true,
        },
        '/badu-im-kouzi': {
          target: env.VITE_API_URL,
          changeOrigin: true,
        },
        '/call-rest': {
          target: env.VITE_API_URL,
          changeOrigin: true,
        },
      },
    },
    plugins: [vue(), vueJsx(), vueDevTools(), UnoCSS()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    define: {
      APP_URL: JSON.stringify(env.VITE_API_URL),
      APP_MODE: JSON.stringify(env.VITE_APP_MODE),
    },
  }
})
